//
//  SLInformationTableViewCell.m
//  StarLight
//
//  Created by Duke.wu on 16/5/17.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLInformationTableViewCell.h"

@interface SLInformationTableViewCell ()

@property (nonatomic, strong) UIImageView *leftImageView;

@property (nonatomic, strong) UILabel *newsTitleLabel;

@property (nonatomic, strong) UILabel *newsDetailLabel;

@property (nonatomic, strong) UILabel *dateLabel;

@end

@implementation SLInformationTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [self.contentView addSubview:self.leftImageView];
    [self.contentView addSubview:self.newsTitleLabel];
    [self.contentView addSubview:self.newsDetailLabel];
    [self.contentView addSubview:self.dateLabel];
    [self setUpConstrains];
  }
  return self;
}

- (void)setUpConstrains{
  [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.top.equalTo(self.contentView).offset(20);
    make.size.mas_equalTo(CGSizeMake(78, 78));
  }];
  
  [self.newsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.equalTo(self.contentView).offset(-20);
    make.left.equalTo(self.leftImageView.mas_right).offset(16);
    make.top.equalTo(self.leftImageView).offset(13);
  }];
  
  [self.newsDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.newsTitleLabel.mas_bottom).offset(13);
    make.left.equalTo(self.newsTitleLabel);
    make.right.equalTo(self.newsTitleLabel);
  }];
  
}


- (void)configInfoCellWith:(SLNewsModel *)model{
  
  if (model.imagurl.length <= 0) {
    self.leftImageView.hidden = YES;
    [self.leftImageView mas_updateConstraints:^(MASConstraintMaker *make) {
      make.size.mas_equalTo(CGSizeMake(0, 78));
    }];
  }else{
    self.leftImageView.hidden = NO;
    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.imagurl]];
    [self.leftImageView mas_updateConstraints:^(MASConstraintMaker *make) {
      make.size.mas_equalTo(CGSizeMake(78, 78));
    }];
  }
  
  self.newsTitleLabel.text = model.title;
  self.newsDetailLabel.text = model.content;
  self.dateLabel.text = [NSString stringWithFormat:@"发布于: %@",model.time];
  
}





#pragma mark - getter

- (UIImageView *)leftImageView{
  if (!_leftImageView) {
    _leftImageView = [UIImageView new];
    _leftImageView.backgroundColor = SLYellowColor;
  }
  return _leftImageView;
}

- (UILabel *)newsTitleLabel{
  if (!_newsTitleLabel) {
    _newsTitleLabel = [UILabel labelwithBoldFontSize:16 textColor:[UIColor blackColor] text:@""];
  }
  return _newsTitleLabel;
}

- (UILabel *)newsDetailLabel{
  if (!_newsDetailLabel) {
    _newsDetailLabel = [UILabel labelWithFontSize:12 textColor:SLGrayColor];
    _newsDetailLabel.numberOfLines = 2;
  }
  return _newsDetailLabel;
}


- (UILabel *)dateLabel{
  if (!_dateLabel) {
    _dateLabel = [UILabel labelWithFontSize:10 textColor:SLGrayColor];
  }
  return _dateLabel;
}

@end





